import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/house/house_list.dart';
import 'package:flutter_enjoy_plus/pages/house/location_list.dart';
import 'package:flutter_enjoy_plus/pages/login/index.dart';
import 'package:flutter_enjoy_plus/pages/notfound/index.dart';
import 'package:flutter_enjoy_plus/pages/notice/index.dart';
import 'package:flutter_enjoy_plus/pages/tab_bar_page.dart';
import 'package:flutter_enjoy_plus/profile/index.dart';
import 'package:flutter_enjoy_plus/router/index.dart';
import 'package:flutter_enjoy_plus/utils/token.dart';

void main() {
  runApp(MaterialApp(
    // home: MinePage(),
    // ========routes精简后
    routes: RouterManager.routes
    // ========routes精简前
    // {
    //   '/': (context) => const TabBarPage(),
    //   '/detail': (context) => const NoticeDetail(),
    //   '/login': (context) => const LoginPage(),
    //   // '/profile':(context) => ProfilePage()
    // }
    ,
    // 除了routes的页面随便访问，其他页面需要先进入此函数
    onGenerateRoute: (settings) {
      // 必须先是函数形式，以接收settings
      return RouterManager.generateRoute(settings);
    },
    // (settings) {
    //   // 目标：没有token的拦截到登录页，有token才能访问
    //   final token = TokenManager().getToken() ?? '';
    //   // 是否有token。有token随便，无token跳转登录页
    //   if (token.isEmpty && settings.name != '/login') {
    //     // 若无token,且非登录页。则跳转登录页
    //     // if (settings.name != '/login') {
    //     return MaterialPageRoute(builder: (context) => const LoginPage());
    //     // }
    //   }
    //   // 如果有token，去想去的地方（手动设置）
    //   if (settings.name == '/profile') {
    //     return MaterialPageRoute(
    //         builder: (context) =>
    //             ProfilePage(userInfo: settings.arguments as Map));
    //   }

    //   if (settings.name == '/house_list') {
    //     return MaterialPageRoute(builder: (context) => const HouseList());
    //   }

    //   if (settings.name == '/location_list') {
    //     return MaterialPageRoute(builder: (context) => const LocationList());
    //   }
    //   // 有token，但与任何路径都不匹配
    //    return MaterialPageRoute(builder: (context) =>const NotFound());
    // },

  // 初始化加载的路由
    initialRoute: '/',
  ));
}
